package com.tuanzi.service.impl;

import com.tuanzi.ResultVo.ResultVO;
import com.tuanzi.dao.FlowerPotMapper;
import com.tuanzi.entity.FlowerPot;
import com.tuanzi.service.TestService;
import com.tuanzi.utils.Status;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author tuanzi
 * @version 1.0
 * @date 2022/3/30 17:35
 */

@Service
public class TestServiceImpl implements TestService {

    @Resource
    private FlowerPotMapper flowerPotMapper;

    /**
     * 用来测试
     *
     *  获取所有的花盆
     *  获取指定用户的所有花盆
     *
     *  一般来说，查询并不需要指定事务
     */

    @Override
    public ResultVO getAllPots() {
        List<FlowerPot> flowerPots = flowerPotMapper.selectAllPots();
        ResultVO vo = new ResultVO(flowerPots);
        if(vo == null){
            vo.setStatus(Status.GETFAILED);
        }else {
            vo.setStatus(Status.GETSUCCESS);
        }
        return vo;
    }

    @Override
    public ResultVO getUSerPots(Integer uid) {
        List<FlowerPot> flowerPots = flowerPotMapper.selectUserPots(uid);
        ResultVO vo = new ResultVO(flowerPots);
        if (flowerPots == null){
            vo.setStatus(Status.GETFAILED);
        }else {
            vo.setStatus(Status.GETSUCCESS);
        }
        return vo;
    }

}
